//
//  LZVideoDetailTagsCell.m
//  LzzizDemo
//
//  Created by xbnzd on 16/11/3.
//  Copyright © 2016年 xbnzd. All rights reserved.
//

#import "LZVideoDetailTagsCell.h"
#import "GiftListLabel.h"

@interface LZVideoDetailTagsCell()
@property (weak, nonatomic) IBOutlet UILabel *tagCellLabel;
@property (weak, nonatomic) IBOutlet GiftListLabel *tagsLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *tagContentLabelLeading;

@end

@implementation LZVideoDetailTagsCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [self configureLabel];
    // Initialization code
    
    CGFloat leadingSpace = [self getMaxWidth];
    self.tagContentLabelLeading.constant = leadingSpace + 20;
    self.tagCellLabel.text = LZLocalizedString(@"tag", nil);
    self.tagsLabel.preferredMaxLayoutWidth = SCREEN_WIDTH - leadingSpace - 30;
}

- (void)loadTags:(NSString *)tags
{
    [self setTagsLabelText:tags];
}

- (void)setTagsLabelText:(NSString *)text
{
    if (text.length <= 0) {
        return;
    }
    extern CGFloat textLineSpace;
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:text];
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    
    [style setLineSpacing:textLineSpace];
    [style setLineBreakMode:NSLineBreakByWordWrapping];
    [style setAlignment:NSTextAlignmentLeft];
    
    [attStr addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, attStr.length)];
    self.tagsLabel.attributedText = attStr;
}

#pragma mark -
#pragma mark configure label
- (void)configureLabel
{
    [self.tagsLabel setVerticalAlignment:VerticalAlignmentTop];
}

- (CGFloat)getMaxWidth
{
    CGSize s = [LZLocalizedString(@"ingredients", nil) boundingRectWithSize:CGSizeMake(MAXFLOAT, 25) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:15]} context:nil].size;
    
    return s.width;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
